package com.boarsoft.boar.office.work.action;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.boarsoft.bean.LogonI;
import com.boarsoft.bean.ReplyInfo;
import com.boarsoft.boar.office.entity.OfficeWorkInfo;
import com.boarsoft.boar.office.entity.OfficeWorkLog;
import com.boarsoft.boar.office.work.OfficeWorkLogBiz;
import com.boarsoft.common.Authorized;
import com.boarsoft.common.Util;
import com.boarsoft.common.dao.PagedResult;
import com.boarsoft.web.controller.BaseController;
import com.boarsoft.web.login.Logined;

@Component
@RestController
@RequestMapping("/work/log")
public class OfficeWorkLogAction extends BaseController {
	@Autowired
	private OfficeWorkLogBiz officeWorkLogBiz;

	@RequestMapping("/get.do")
	@Authorized(code = "office.work.get")
	public ReplyInfo<Object> get(String id) {
		OfficeWorkLog o = officeWorkLogBiz.get(id);
		// o.setOwner(this.getSysUser(o.getUserId()));
		return new ReplyInfo<Object>(true, o);
	}

	@RequestMapping("/save.do")
	@Authorized(code = "office.work.log.save")
	public ReplyInfo<Object> save(@Logined LogonI<String> logon, OfficeWorkLog o) {
		o.setUserId(logon.getId());
		if (Util.strIsEmpty(o.getId())) {
			officeWorkLogBiz.add(o);
		} else {
			officeWorkLogBiz.update(o);
		}
		return ReplyInfo.SUCCESS;
	}

	@RequestMapping("/list.do")
	@Authorized(code = "office.work.log.list")
	public ReplyInfo<Object> index(String taskId, String userId, String date, String key, String orderBy, int pageNo,
			int pageSize) {
		PagedResult<OfficeWorkInfo> pr = officeWorkLogBiz.list(//
				taskId, userId, date, key, orderBy, pageNo, pageSize);
		for (OfficeWorkInfo o : pr.getList()) {
			o.setOwner(this.getSysUser(o.getOwnerId()));
		}
		return new ReplyInfo<Object>(true, pr);
	}
}